Jenkins Kata 1: Create a Job
Learn how to create and run the job and set up source control parameters.
We'll cover the following
Jenkins organizes work into jobs. This kata will walk us through setting up a simple job using the web-storelist repository from the Git katas.
Step 1: Create a new job#
The following are the steps to create a new job:
- Return to the Jenkins homepage.
- Click the “New Item” link.
- Enter “web-storelist” in the “Item Name” field.
- Select “Freestyle project.”
- Click “OK.”
Jenkins organizes work into jobs. A single job can do several things, including:
- Pull code from a source control repository.
- Run shell scripts.
- Run other jobs.
- Run custom actions after a job is complete.
Executing a job is referred to as building the job. The term build is typically associated with compiling source code into an executable. Jenkins jobs do run compile steps. However, they can do much more than just compile. Jenkins jobs are used to run tests, interact with other systems, and deploy applications to their runtime environments.
Step 2: Set up source control parameters#
Click the “Source Code Management” tab.
Every job in Jenkins has a default set of configurations:
- General: This includes the job name, description, and basic settings.
- Source code management: This defines a source code repository that will be pulled from at the start of each job build.
- Build triggers: This defines automated triggers that execute the job.
- Build environment: These are options that affect the way the job is run.
- Build: This is the primary action(s) of the job.
- Post-build actions: These are actions that are executed after the main build actions if the job doesn’t return an error.
To proceed, select “Git” from the list. Then:
- Enter the repository URL: “http://localhost:3000/cody.coder/web-storelist.git”
- Click “Save.”
Jenkins jobs are commonly configured to act on code. The first thing these typical jobs must do, therefore, is to get an updated copy of the code.
The settings defined in this step will make the web-storelist job execute a git pull command on the Gogs server before all other actions defined by the job. The remaining steps of the job then have the most current version of the code available to them.
Step 3: Run the job#
Click on “Build Now” on the left.
The web-storelist job now has source control configured, but no build steps have been defined. What, then, happens when we build? We can see a successful build in the build history (the blue dot indicates a successful build), so what did the job do?
The source control management configuration we set in the previous step will make this job get the current version of the code. Even with no build steps defined, the source control update action is executed. The next step will demonstrate how to view this job’s workspace.
Click “Workspace” on the left side.
All Jenkins jobs have a workspace. The workspace is a folder on the Jenkins system where all the work of the job is performed. This includes pulling the source code, executing work on the code (build, test), and executing commands related to the job. Think of the workspace as the home base folder of the job.
Now that the job has been built, we can see that the workspace has been populated with files. These are the files in the web-storelist repository hosted in Gogs. Those who’ve completed the Git katas will recognize the storelist.htm file.
Quiz Yourself on Continuous Integration and Jenkins
Jenkins Kata 2: Build Steps